home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.5)
-
- import os
- import unittest
- import subscription
- from test.framework import DemocracyTestCase
- SAMPLE_RSS_SUBSCRIPTION_URL_1 = 'http://www.domain-1.com/videos/rss.xml'
- SAMPLE_RSS_SUBSCRIPTION_URL_2 = 'http://www.domain-2.com/videos/rss.xml'
- SAMPLE_ATOM_SUBSCRIPTION_URL_1 = 'http://www.domain-1.com/videos/atom.xml'
- SAMPLE_ATOM_SUBSCRIPTION_URL_2 = 'http://www.domain-2.com/videos/atom.xml'
- INVALID_CONTENT_1 = u'\nThis is not XML...\n'
- INVALID_CONTENT_2 = u'<?xml version="1.0" encoding="UTF-8" ?>\n<this-is-bogus-xml-syntax>\n yes indeed\n</this-is-bogus-xml-syntax>\n'
- ATOM_LINK_CONSTRUCT_IN_RSS = u'<?xml version="1.0" encoding="UTF-8" ?>\n<rss version="2.0">\n <channel>\n <title>Dummy RSS Feed</title>\n <link>http://www.getdemocracy.com</link>\n <description>A dummy RSS feed to test USM subscription</description>\n <atom:link \n xmlns:atom="http://www.w3.org/2005/Atom"\n rel="self" \n type="application/rss+xml" \n title="Sample Dummy RSS Feed" \n href="%s" />\n </channel>\n</rss>\n' % SAMPLE_RSS_SUBSCRIPTION_URL_1
- ATOM_LINK_CONSTRUCT_IN_ATOM = u'<?xml version="1.0" encoding="UTF-8" ?>\n<feed xmlns="http://www.w3.org/2005/Atom">\n <title>Dummy Atom Feed</title>\n <updated>2006-05-28T11:00:00Z</updated>\n <author><name>Luc Heinrich</name></author>\n <id>urn:uuid:D7732206-B0BF-4FAF-B2CE-FC25C6C5548F</id>\n <link \n xmlns:atom="http://www.w3.org/2005/Atom"\n rel="self" \n type="application/rss+xml" \n title="Sample Dummy Atom Feed" \n href="%s" />\n</feed>\n' % SAMPLE_ATOM_SUBSCRIPTION_URL_1
- REFLEXIVE_AUTO_DISCOVERY_IN_RSS = u'<?xml version="1.0" encoding="UTF-8" ?>\n<rss version="2.0">\n <channel>\n <title>Dummy RSS Feed</title>\n <description>\n A dummy RSS feed to test USM Reflexive Auto Discovery\n </description>\n <link>reflexive-auto-discovery-page-rss.html</link>\n </channel>\n</rss>\n'
- REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME = 'reflexive-auto-discovery-page-rss.html'
- REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS = u'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" \n\t "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n\t\t<title>Reflexive Auto Discovery Page</title>\n\t <link rel="alternate" type="application/rss+xml" title="RSS" href="%s" />\n\t</head>\n\t<body>\n\t This place intentionally (almost) blank... :)\n\t</body>\n</html>\n' % SAMPLE_RSS_SUBSCRIPTION_URL_1
- REFLEXIVE_AUTO_DISCOVERY_IN_ATOM = u'<?xml version="1.0" encoding="UTF-8" ?>\n<feed xmlns="http://www.w3.org/2005/Atom">\n <title>Dummy Atom Feed</title>\n <updated>2006-05-28T11:00:00Z</updated>\n <author><name>Luc Heinrich</name></author>\n <id>urn:uuid:D7732206-B0BF-4FAF-B2CE-FC25C6C5548F</id>\n <link \n xmlns:atom="http://www.w3.org/2005/Atom"\n rel="alternate" \n type="application/atom+xml" \n title="Sample Dummy AutoDiscovery Feed" \n href="reflexive-auto-discovery-page-atom.html" />\n</feed>\n'
- REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME = 'reflexive-auto-discovery-page-atom.html'
- REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM = u'<?xml version="1.0" encoding="utf-8"?>\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" \n\t "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\t<head>\n\t\t<meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n\t\t<title>Reflexive Auto Discovery Page</title>\n\t <link rel="alternate" type="application/atom+xml" title="RSS" href="%s" />\n\t</head>\n\t<body>\n\t This place intentionally (almost) blank... :)\n\t</body>\n</html>\n' % SAMPLE_ATOM_SUBSCRIPTION_URL_1
- OPML_FLAT = u'<?xml version="1.0" encoding="utf-8"?>\n<opml version="1.0">\n <head>\n <title>Sample OPML Flat Subscription List</title>\n </head>\n <body>\n <outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" />\n <outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" />\n <outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />\n <outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />\n </body>\n</opml>\n' % (SAMPLE_RSS_SUBSCRIPTION_URL_1, SAMPLE_ATOM_SUBSCRIPTION_URL_1, SAMPLE_RSS_SUBSCRIPTION_URL_2, SAMPLE_ATOM_SUBSCRIPTION_URL_2)
- OPML_NESTED = u'<?xml version="1.0" encoding="utf-8"?>\n<opml version="1.0">\n <head>\n <title>Sample OPML Flat Subscription List</title>\n </head>\n <body>\n <outline text="folder 1">\n <outline text="Sample Dummy RSS Feed 1" type="rss" xmlUrl="%s" />\n <outline text="folder1-1">\n <outline text="Sample Dummy Atom Feed 1" type="rss" xmlUrl="%s" />\n </outline>\n </outline>\n <outline text="folder 2">\n <outline text="folder2-1">\n <outline text="Sample Dummy RSS Feed 2" type="rss" xmlUrl="%s" />\n </outline>\n <outline text="Sample Dummy Atom Feed 2" type="rss" xmlUrl="%s" />\n </outline>\n </body>\n</opml>\n' % (SAMPLE_RSS_SUBSCRIPTION_URL_1, SAMPLE_ATOM_SUBSCRIPTION_URL_1, SAMPLE_RSS_SUBSCRIPTION_URL_2, SAMPLE_ATOM_SUBSCRIPTION_URL_2)
-
- class TestSubscription(DemocracyTestCase):
- subscription.reflexiveAutoDiscoveryOpener = open
-
- def testInvalidSubscriptions(self):
- urls = subscription.parseFile('this-file-does-not-exist.xml')
- self.assert_(urls is None)
- urls = subscription.parseContent(INVALID_CONTENT_1)
- self.assert_(urls is None)
- urls = subscription.parseContent(INVALID_CONTENT_2)
- self.assert_(urls is None)
-
-
- def testAtomLinkConstructInRSS(self):
- urls = subscription.parseContent(ATOM_LINK_CONSTRUCT_IN_RSS)
- self.assert_(len(urls) == 1)
- self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
-
-
- def testAtomLinkConstructInAtom(self):
- urls = subscription.parseContent(ATOM_LINK_CONSTRUCT_IN_ATOM)
- self.assert_(len(urls) == 1)
- self.assert_(urls[0] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
-
-
- def testReflexiveAutoDiscoveryInRSS(self):
- pageFile = file(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME, 'w')
- pageFile.write(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS)
- pageFile.close()
- urls = subscription.parseContent(REFLEXIVE_AUTO_DISCOVERY_IN_RSS)
- self.assert_(len(urls) == 1)
- self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
- os.remove(REFLEXIVE_AUTO_DISCOVERY_PAGE_RSS_FILENAME)
-
-
- def testReflexiveAutoDiscoveryInAtom(self):
- pageFile = file(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME, 'w')
- pageFile.write(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM)
- pageFile.close()
- urls = subscription.parseContent(REFLEXIVE_AUTO_DISCOVERY_IN_ATOM)
- self.assert_(len(urls) == 1)
- self.assert_(urls[0] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
- os.remove(REFLEXIVE_AUTO_DISCOVERY_PAGE_ATOM_FILENAME)
-
-
- def testFlatOPMLSubscriptions(self):
- urls = subscription.parseContent(OPML_FLAT)
- self.assert_(len(urls) == 4)
- self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
- self.assert_(urls[1] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
- self.assert_(urls[2] == SAMPLE_RSS_SUBSCRIPTION_URL_2)
- self.assert_(urls[3] == SAMPLE_ATOM_SUBSCRIPTION_URL_2)
-
-
- def testNestedOPMLSubscriptions(self):
- urls = subscription.parseContent(OPML_NESTED)
- self.assert_(len(urls) == 4)
- self.assert_(urls[0] == SAMPLE_RSS_SUBSCRIPTION_URL_1)
- self.assert_(urls[1] == SAMPLE_ATOM_SUBSCRIPTION_URL_1)
- self.assert_(urls[2] == SAMPLE_RSS_SUBSCRIPTION_URL_2)
- self.assert_(urls[3] == SAMPLE_ATOM_SUBSCRIPTION_URL_2)
-
-
-
- class TestFindSubscribeLinks(DemocracyTestCase):
-
- def testDifferstHost(self):
- url = 'http://youtoob.com'
- self.assertEquals(subscription.findSubscribeLinks(url), ('none', []))
-
-
- def testNoLinks(self):
- url = 'http://subscribe.getdemocracy.com/'
- self.assertEquals(subscription.findSubscribeLinks(url), ('feed', []))
-
-
- def testLinkInPath(self):
- url = 'http://subscribe.getdemocracy.com/http%3A//www.myblog.com/rss'
- self.assertEquals(subscription.findSubscribeLinks(url), ('feed', [
- 'http://www.myblog.com/rss']))
-
-
- def testLinkInQuery(self):
- url = 'http://subscribe.getdemocracy.com/?url1=http%3A//www.myblog.com/rss'
- self.assertEquals(subscription.findSubscribeLinks(url), ('feed', [
- 'http://www.myblog.com/rss']))
-
-
- def testMultipleLinksInQuery(self):
- url = 'http://subscribe.getdemocracy.com/?url1=http%3A//www.myblog.com/rss&url2=http%3A//www.yourblog.com/atom&url3=http%3A//www.herblog.com/scoobydoo'
- (type, links) = subscription.findSubscribeLinks(url)
- self.assertEquals(type, 'feed')
- self.assertEquals(set(links), set([
- 'http://www.myblog.com/rss',
- 'http://www.yourblog.com/atom',
- 'http://www.herblog.com/scoobydoo']))
-
-
- def testQueryGarbage(self):
- url = 'http://subscribe.getdemocracy.com/?url1=http%3A//www.myblog.com/rss&url2=http%3A//www.yourblog.com/atom&url3=http%3A//www.herblog.com/scoobydoo&foo=bar&extra=garbage'
- (type, links) = subscription.findSubscribeLinks(url)
- self.assertEquals(type, 'feed')
- self.assertEquals(set(links), set([
- 'http://www.myblog.com/rss',
- 'http://www.yourblog.com/atom',
- 'http://www.herblog.com/scoobydoo']))
-
-
- def testChannelGuideLinks(self):
- url = 'http://subscribe.getdemocracy.com/channelguide.php?url1=http%3A//www.mychannelguide.com/'
- self.assertEquals(subscription.findSubscribeLinks(url), ('guide', [
- 'http://www.mychannelguide.com/']))
-
-
- def testDownloadLinks(self):
- url = 'http://subscribe.getdemocracy.com/download.php?url1=http%3A//www.myblog.com/videos/cats.ogm'
- self.assertEquals(subscription.findSubscribeLinks(url), ('download', [
- 'http://www.myblog.com/videos/cats.ogm']))
-
-
-